import junit.framework.TestCase;

import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;

import edu.towson.cosc603.coffeemaker.CoffeeMaker;
import edu.towson.cosc603.coffeemaker.Recipe;



public class CoffeeMakerTest extends TestCase {

			CoffeeMaker cm;
			Recipe caramela;
			Recipe caramelb;
			Recipe caramelc;
			Recipe carameld;
			@BeforeClass
			public void setUp() throws Exception {
				cm = new CoffeeMaker();
				caramela = new Recipe();
				caramelb = new Recipe();
				caramelc = new Recipe();
				carameld = new Recipe();
				caramela.setAmtChocolate(3);
				caramela.setAmtCoffee(3);
				caramela.setAmtMilk(3);
				caramela.setAmtSugar(3);
				caramela.setName("caramela");
				caramela.setPrice(3);
				
				
				caramelb.setAmtChocolate(4);
				caramelb.setAmtCoffee(4);
				caramelb.setAmtMilk(4);
				caramelb.setAmtSugar(4);
				caramelb.setName("caramelb");
				caramelb.setPrice(2);
				
				
				caramelc.setAmtChocolate(5);
				caramelc.setAmtCoffee(5);
				caramelc.setAmtMilk(5);
				caramelc.setAmtSugar(5);
				caramelc.setName("caramelc");
				caramelc.setPrice(2);
				
				
				carameld.setAmtChocolate(6);
				carameld.setAmtCoffee(6);
				carameld.setAmtMilk(6);
				carameld.setAmtSugar(6);
				carameld.setName("carameld");
				carameld.setPrice(4);
				
				
			}

			@After
			public void tearDown() throws Exception {
			}

			@Test
			public void testAddRecipe() {
				//Successful addition of recipe
				assertTrue(cm.addRecipe(caramela));
				//can not add the same item.
				assertFalse(cm.addRecipe(caramela));
				
				//Adding more recipe in the coffee maker.
				assertTrue(cm.addRecipe(caramelb));
				assertTrue(cm.addRecipe(caramelc));
				assertTrue(cm.addRecipe(carameld));
				//Checking if overriding recipe is false or not.
				Recipe re = new Recipe();
				assertFalse(cm.addRecipe(re));
				
			}

			@Test
			public void testDeleteRecipe() {
				//Null item cannot be deleted.
				assertFalse(cm.deleteRecipe(null));
				//Cannot delete a non-existing item.
				assertFalse(cm.deleteRecipe(caramela));
				
				//Existing item cannot be deleted.
				cm.addRecipe(caramela);
				assertTrue(cm.deleteRecipe(caramela));
				//Chekcing the deletion again.
				assertFalse(cm.deleteRecipe(caramela));
			}

			@Test
			public void testEditRecipe() {
				//Cannot edit existing recipe.
				assertFalse(cm.editRecipe(caramelb, caramela));
				//Successfully edited the recipe.
				cm.addRecipe(caramela);
				assertTrue(cm.editRecipe(caramela, caramelb));
				
			}

			@Test
			public void testAddInventory() {
				//Checking invalid cases.
				assertFalse(cm.addInventory(-1, 1, 1, 1));
				assertFalse(cm.addInventory(1, -1, 1, 1));
				assertFalse(cm.addInventory(1, 1, -1, 1));
				assertFalse(cm.addInventory(1, 1, 1, -1));
				
				//Checking valid cases.
				assertTrue(cm.addInventory(1, 1, 1, 1));		
			}


			@Test
			public void testMakeCoffee() {
				assertEquals(1,cm.makeCoffee(caramela, 1));//Insufficient money.
				assertEquals(0, cm.makeCoffee(caramela, 3));//0 refund.
				Recipe re = new Recipe();
				re.setAmtChocolate(16);
				//Not enough inventory for the recipe.
				assertEquals(1,cm.makeCoffee(re, 1));
				
				
			}
			
			@Test
			public void testGetName(){
				cm.addRecipe(caramela);
				assertEquals(caramela, cm.getRecipeForName(caramela.getName())); //valid case
				
				//Invalid condition.
				Recipe re = cm.getRecipeForName("COOKIE_DONOTEXIST");
				assertTrue(re.getName()==null);
				
			}

		}
